﻿using System.Net;
using System.Xml;

namespace Builderator.Core.Components
{
    public class Server
    {
        public string Name
        {
            get;
            set;
        }

        public string Domain
        {
            get;
            set;
        }

        public Server()
        {
            this.Name = Dns.GetHostName();

            this.Domain = this.Name;
        }

        public Server(string xml)
            : this()
        {
            XmlDocument xmlDoc = new XmlDocument();

            xmlDoc.LoadXml(xml);

            XmlElement rootElement = xmlDoc.DocumentElement;

            this.Name = rootElement.GetAttribute("Name");

            this.Domain = rootElement.GetAttribute("Domain");
        }

        public override string ToString()
        {
            XmlDocument xmlDoc = new XmlDocument();

            XmlElement rootElement = xmlDoc.CreateElement("Server");

            xmlDoc.AppendChild(rootElement);

            rootElement.SetAttribute("Name", this.Name);

            rootElement.SetAttribute("Domain", this.Domain);

            return xmlDoc.InnerXml;
        }
    }
}